package fpzhan.plane.program.connect;

import java.io.Serializable;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.Collection;


public final class Param implements Serializable,Cloneable {
    private static final long serialVersionUID = 362498820763181265L;


    private String flowId;

    private  final static Map<String,Map<String,Object>> variables=new HashMap<>();

    protected Param(String flowId) {
        this.flowId=flowId;
        variables.put(flowId,new HashMap<>());
    }


    public Object get(String key){
        return variables.get(flowId).get(key);
    }

    public <T extends Object> T get(String key,Class<T> tClass){
        return tClass.cast(variables.get(flowId).get(key));
    }


    public Param put(String key, Object obj){
        variables.get(flowId).put(key,obj);
        return this;
    }

    public Map<String,Object> variables(){
        return this.variables.get(flowId);
    }

    public Set<Map.Entry<String,Object>> entrySet(){
        return this.variables.get(flowId).entrySet();
    }

    public Set<String> keySet(){
        return this.variables.get(flowId).keySet();
    }

    public Param remove(String... keys){
        for (String key:keys)this.variables.get(flowId).remove(key);
        return this;
    }



    public int size(){
        return this.variables.get(flowId).size();
    }

    public boolean isEmpty(){
        return this.variables.get(flowId).isEmpty();
    }

    public boolean containsKey(Object key){
        return this.variables.get(flowId).containsKey(key);
    }

    public boolean containsValue(Object value){
        return this.variables.get(flowId).containsKey(value);
    }

    public Param putAll(Map<String, Object> m){
        this.variables.get(flowId).putAll(m);
        return this;
    }

    public Param clear(){
        this.variables.get(flowId).clear();
        return this;
    }

    public Collection<Object> values(){
        return this.variables.get(flowId).values();
    }

    public Map<String, Object> getVariables() {
        return variables.get(flowId);
    }

    protected void destroy(){
        variables.remove(flowId);
    }
}
